//
//  Prescription.m
//  demo_3
//
//  Created by 才 陈 on 12-4-2.
//  Copyright (c) 2012年 sjtu. All rights reserved.
//

#import "Prescription.h"

@implementation Prescription

@synthesize count;
@synthesize ingredientType;

-(id) init:(IngredientType *)it :(int)cnt
{
    if(self = [super init])
    {
        count = cnt;
        ingredientType = it;
    }
    
    return self;
}

+(NSArray *) getPrescriptionList:(NSString *)prescriptionStr :(NSDictionary *)ingredientTypes
{
    NSMutableArray *prescriptionList = [NSMutableArray array];
    
    NSArray *ingredientStrs = [prescriptionStr componentsSeparatedByString:@","];
    
    for (NSString *pairStr in ingredientStrs) {
        NSArray *pairs = [pairStr componentsSeparatedByString:@":"];
        int count = [[pairs objectAtIndex:1] intValue];
        IngredientType *ingredientType = [ingredientTypes valueForKey:[pairs objectAtIndex:0]];
        Prescription *prescritpion = [[Prescription alloc] init:ingredientType :count];
        
        [prescriptionList addObject:prescritpion];
    }
    return prescriptionList;

}
@end
